import Vue from "vue";
import VeeValidate, { Validator } from "vee-validate";
import zh_CN from "vee-validate/dist/locale/zh_CN";
import Dictionary from "./dictionary";
import VueI18n from "vue-i18n";

Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: "zh_CN"
});
Vue.use(VeeValidate, {
  i18n,
  i18nRootKey: "validation",
  dictionary: {
    zh_CN
  }
});
/*自动以方法*/
Validator.extend("mobile", {
  getMessage: field => "手机格式不正确",
  validate: value =>
    value.length === 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
});
Validator.extend("phone_code", {
  getMessage: field => "验证码为4位数字",
  validate: value => /^\d{4}$/.test(value)
});
Validator.extend("password", {
  getMessage: field => "密码6-20位,至少包含字母、数字以及标点符号(除空格)两种",
  validate: value =>
    /^(?![\d]+$)(?![a-zA-Z]+$)(?![!#$%^&*,.]+$)[\da-zA-Z!#$%^&*,.]{6,20}$/.test(
      value
    )
});
Validator.extend("zipcode", {
  getMessage: field => "邮编格式不正确",
  validate: value => /^[1-9][0-9]{5}$/.test(value)
});

Validator.extend("bankcard", {
  getMessage: field => "输入一卡通卡号",
  validate: value => /^\d{20}\b/.test(value)
});

// 自定义validate error 信息
Validator.localize(Dictionary);
